package com.lagou.edu.boss.rest.course;

import com.lagou.edu.boss.entity.form.LessonForm;
import com.lagou.edu.boss.service.lesson.ILessonService;
import com.lagou.edu.common.entity.vo.Result;
import com.lagou.edu.course.api.dto.LessonDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "课时内容", produces = "application/json")
@Slf4j
@RestController
@RequestMapping("/course/lesson")
public class LessonController {
    @Autowired
    ILessonService lessonService;

    /**
     * 保存或者更新课程
     * @param lessonForm
     * @return
     */
    @ApiOperation(value = "保存或更新课时")
    @PostMapping(value = "/saveOrUpdate")
    Result saveOrUpdate(@RequestBody LessonForm lessonForm){
        LessonDTO lessonDTO = new LessonDTO();
        BeanUtils.copyProperties(lessonForm,lessonDTO);
        return Result.success(lessonService.saveOrUpdate(lessonDTO));
    }
}
